<template>
    <div>
        房型名称<input type="text" v-model="cs.name">——<select v-model="cs.tyle">
            <option value="">==请选择==</option>
            <option value="启用">启用</option>
            <option value="停用">停用</option>
        </select>
        <input type="button" value="查询" @click="show"> <input type="button" value="清空" @click="kong">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td>门市价格</td>
                    <td>房间号</td>
                    <td>房间数量</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>
                <tr v-for="a in as.row" :key="a.id">
                    <td>{{ a.name }}</td>
                    <td>￥{{ a.money }}</td>
                    <td>{{ a.num }}</td>
                    <td>{{ a.shu }}</td>
                    <td>{{ a.tyle }}</td>
                    <td><input type="button" @click="del(a.id)" value="删除"><input type="button" @click="up(a.id)" value="修改">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div>
        <span>当前{{ cs.pageindex }}页</span>--
        <span>共{{ as.pagecount }}条</span>--
        <span>当前{{ cs.pageindex }}/{{ as.sizecount }}页</span>
        <input type="button" value="首页" @click="fy(1)">
        <input type="button" value="上一页" @click="fy(cs.pageindex - 1)">
        <span v-for="a in as.sizecount" @click="fy(a)">{{ a }}</span>
        <input type="button" value="下一页" @click="fy(cs.pageindex + 1)">
        <input type="button" value="尾页" @click="fy(as.sizecount)">
        <input type="number" v-model="cs.pageindex">
        <input type="button" value="跳转" class="btn btn-warning" @click="fy(cs.pageindex)">
        <select v-model="cs.pagesize" @click="list">
            <option :value="a" v-for="a in page">{{ a }}</option>
        </select>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from "vue";
import moment from 'moment';
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
let page: any = ref([2, 4, 6, 8]);
onMounted(() => {
    show();
})
let cs: any = reactive(
    {
        pageindex: 1,
        pagesize: 2,
        name: '',
        tyle: ''
    }
)
let as: any = reactive(
    {
        pagecount: 0,
        sizecount: 0,
        row: []
    }
)
const fy = (f: any) => {
    if (f < 1) {
        cs.pageindex = 1;
        return;
    }
    if (f > as.sizecount) {
        cs.pageindex = as.sizecount;
        return;
    }
    cs.pageindex = f;
    show();
}
const show = () => {
    axios({
        url: 'https://localhost:7200/api/Emp/show',
        method: 'get',
        params: cs
    })
        .then(res => {
            console.log(res);
            as.pagecount = res.data.pagecount;
            as.sizecount = res.data.sizecount;
            as.row = res.data.row;
        })
        .catch(err => {
            console.log(err);

        })
}
const list = () => {
    show();
}
const kong = () => {
    cs.name = "";
    cs.tyle = "";
}
const del=(id: any) => {
    var f = confirm("确认要删除吗");
    if (f) {
        axios({
            url: 'https://localhost:7200/api/Emp/del',
            method: 'post',
            params: { id: id }
        })
            .then(res => {
                console.log(res);
                if (res.data > 0) {
                    alert("删除成功");
                    router.push("/Show");
                }
            })
            .catch(err=>{
                console.log(err);
                
            })
    }
}
const up=(id:any)=>{
router.push({
    path:'/Update',
    query:{
        id:id
    }
})
}
</script>

<style scoped></style>